#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/12/9 11:18
# @Author  : lizhen
# @Site    : 
# @File    : descriptor.py
# @Software: PyCharm


def has_descriptor_attrs(obj):
    return set(['__get__', '__set__', '__delete__']).intersection(dir(obj))


def is_descriptor(obj):
    return bool(has_descriptor_attrs(obj))


def has_data_descriptor_attrs(obj):
    return set(['__set__', '__delete__']) & set(dir(obj))


def is_data_descriptor(obj):
    return bool(has_data_descriptor_attrs(obj))


class CustomDescriptor:
    def __init__(self, value):
        self.value = value

    def __get__(self, instance, owner):
        return self.value

    def __set__(self, instance, value):
        self.value = value

    def __delete__(self, instance):
        del self.value

    @classmethod
    def run(cls, *args, **kwargs):
        cd = cls(*args, **kwargs)
        print(cd.value)
        cd.value = '123'
        print(cd.value)


def main():
    # CustomDescriptor.run('abc')
    print(is_descriptor(classmethod), is_data_descriptor(classmethod))
    print(is_descriptor(staticmethod), is_data_descriptor(staticmethod))
    print(is_data_descriptor(property))


if __name__ == '__main__':
    main()
